class MinStack(object):

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []
        self.small = []

    def push(self, x):
        """
        :type x: int
        :rtype: void
        """
        self.stack.append(x)
        if self.small:
            if x<=self.small[-1]:
                self.small.append(x)
        else:
            self.small.append(x)

    def pop(self):
        """
        :rtype: void
        """
        val = self.stack[-1]
        if val==self.small[-1]:
            self.small.pop()
        self.stack.pop()
        return val

    def top(self):
        """
        :rtype: int
        """
        return self.stack[-1]

    def getMin(self):
        """
        :rtype: int
        """
        return self.small[-1]